package com.design.pattern.command.drawer;

import com.design.pattern.command.command.MacroCommand;

import java.awt.*;

/**
 * 长沙先飞信息科技有限公司<br>
 * Created with IntelliJ IDEA.<br>
 * Date:2024/6/20<br>
 * Time:12:33<br>
 * 功能描述：<br>
 *
 * @author huang hou chun
 * @since JDK 1.8 <br>
 * Copyright (c) 2023 www.csxfrj.com System Incorporated All Rights Reserved.
 */
public class DrawCanvas extends Canvas implements Drawable {

    // 颜色
    private Color color = Color.red;
    // 要绘制圆的半径
    private int radius = 6;
    // 命令的历史记录
    private MacroCommand history;

    public DrawCanvas(int width, int height, MacroCommand history) {
        setSize(width, height);
        setBackground(Color.white);
        this.history = history;
    }

    // 重新全部绘制
    public void paint() {
        history.execute();
    }

    // 绘制
    @Override
    public void draw(int x, int y) {
        Graphics g = getGraphics();
        // 指定颜色
        g.setColor(color);
        // 画圆点
        g.fillOval(x - radius, y - radius, radius * 2, radius * 2);
    }
}
